<template>
  <div>
    <el-tabs v-model="activeName" type="card" >
      <el-tab-pane label="提梁机" name="first">
        <el-row>
          <el-col :span="14">
            <basic-container>
              <div>
                <p>
                  <img src="/jia0.png"/>
                </p>
              </div>
            </basic-container>
          </el-col>
          <el-col :span="10">
            <el-row>
              <basic-container>
                <div class="el-font-size">
                  <span><el-tag>提梁机应力状态监测系统</el-tag></span>
                  <el-divider content-position="left">
                    <i class="el-icon-star-off"/>
                  </el-divider>
                  <div>
                    <el-table :data="listBridge" style="width: 100%" :row-class-name="tableRowClassName">
                      <el-table-column  prop="name"  label="测点"  min-width="30%" align="center"></el-table-column>
                      <el-table-column  prop="sampleValue"  label="应力值(με)"  min-width="18%"></el-table-column>
                      <el-table-column  prop="statusTypeName"  label="状态"  min-width="20%"></el-table-column>

                      <el-table-column label="操作" align="center" min-width="32%">
                        <template slot-scope="scope">
                          <el-button size="mini" type="warning" @click="onclickProp(scope.row.channelId)">属性</el-button>
                          <el-button size="mini" type="success" @click="onclickData( scope.row.channelId)">数据</el-button>
                        </template>
                      </el-table-column>
                    </el-table>

                  </div>
                </div>
              </basic-container>
            </el-row>
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>



  </div>
</template>

<script>
  import {mapGetters} from "vuex";
  import {getDeviceByType} from "@/api/stress/device";
  import {getChannelVibrationPosition} from "@/api/stress/channel"
  import website from '@/config/website';

  var Stomp = require('stompjs');
  var SockJS = require('sockjs-client');
  var stompClient = null;
  let that = null;
  export default {
    name: "wel",
    data() {
      return {
        activeName: 'first',
        listBridge:[],
        bridge:13 //提梁机
      };
    },
    computed: {
      ...mapGetters(["userInfo"]),
    },
    destroyed(){
      this.disconnect()

    },
    mounted() {
      // 非租户模式默认加载管理组数据
      if (!website.tenantMode) {
        this.initData(website.tenantId);
      }
      that = this;
      //建立连接
      this.connection()
    },
    methods: {
      initData(tenantId) {
        getDeviceByType(tenantId,this.bridge).then(res => {
          this.getBridgeData(res.data.data.id);
        });
      },
      getBridgeData(id){
        getChannelVibrationPosition(id).then(res => {
          this.listTower = res.data.data
        });
      },
      onclickProp(id){
        this.$router.push({path: `/work/stress/show/prop/${id}`});
      },
      onclickData(id){
        this.$router.push({path: `/work/stress/show/data/${id}`});
      },
      //建立连接
      connection() {
        //var socket = new SockJS('http://127.0.0.1:80/ws');
        var socket = new SockJS('http://119.3.122.166:39000/ws');
        stompClient = Stomp.over(socket);

        stompClient.connect({}, function() {
          stompClient.subscribe('/user/000000/queue/getResponse',function(response) {
            const res = JSON.parse(response.body)
            if (res.bridgeType === 13){
              that.listBridge = res.bridgeList
            }
          });
        }, (err) => {
          //console.log(err);
        });
      },
      // 断开连接
      disconnect(){
        if (stompClient != null) {
          stompClient.disconnect();
          console.log("Disconnected");
        }
      },
      tableRowClassName({row}) {
        const statusTypeName = row.statusTypeName
        if (statusTypeName === "正常") {
          return '';
        } else {
          return 'warning-row';
        }
      }
    },
  };
</script>

<style>
  .el-font-size {
    font-size: 14px;
  }
  .el-table .warning-row {
    background: oldlace;
  }
  /*
    .box{
      width: 50%;
      margin: 50px auto;
    }
    .img-box{
      width: 100%;
      position:relative;
      z-index:1;
    }
    .img-box img{
      position:absolute;
      top:0;
      bottom:0;
      left:0;
      right:0;
      width:100%;
      margin:auto;
      z-index: -1;
      *zoom:1;
    }
    .img-box:before {
      content: "";
      display: inline-block;
      padding-bottom: 100%;
      width: 0.1px; 必须要有数值，否则无法把高度撑起来
    vertical-align: middle;
  }*/
</style>

